package ru.gelin.android.multiplier;

import android.database.Cursor;

import java.text.ParseException;
import java.util.Date;

import static ru.gelin.android.multiplier.OperationsHistory.DATE_FORMAT;
import static ru.gelin.android.multiplier.OperationsHistoryOpenHelper.*;

public class OperationsHistoryItem {

    public Operation operation;
    public Date date;

    public OperationsHistoryItem(Operation operation, Date date) {
        this.operation = operation;
        this.date = date;
    }

    public OperationsHistoryItem(Operation operation) {
        this(operation, new Date());
    }

    public OperationsHistoryItem(Cursor cursor) throws ParseException {
        this.date = DATE_FORMAT.parse(cursor.getString(cursor.getColumnIndex(DATE_COLUMN)));
        this.operation = new Operation();
        this.operation.setNumber1(cursor.getDouble(cursor.getColumnIndex(NUM1_COLUMN)));
        this.operation.setNumber2(cursor.getDouble(cursor.getColumnIndex(NUM2_COLUMN)));
        this.operation.setType(Operation.Type.valueOf(cursor.getString(cursor.getColumnIndex(OP_COLUMN))));
    }

}
